package de.lulusoft.anothertorrent.core.rtorrent;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.io.Serializable;
import java.text.DecimalFormat;

import de.lulusoft.anothertorrent.core.servers.Server;

public class Torrent implements Serializable{

	private static final long serialVersionUID = -5887046257815822566L;
	
	private String base_filename = "";
	private String base_path = "";
	private Long bytes_done;
	private Long chunk_size;
	private Long chunks_hashed;
	private Long complete;
	private Long completed_bytes;
	private Long completed_chunks;
	private String connection_current;
	private String connection_leech;
	private String connection_seed;
	private Long creation_date = null;
	private String directory = "";
	private Long down_rate;
	private Long down_total;
	private Long free_diskspace;
	private String hash = "";
	private Long hashing = null;
	private Long ignore_commands = null;
	private Long left_bytes;
	private String local_id = null;
	private String local_id_html = null;
	private Long max_file_size;
	private String message = null;
	private Long peers_min;
	private String name = "";
	private Long peer_exchange = null;
	private Long peers_accounted = null;
	private Long peers_complete = null;
	private Long peers_connected = null;
	private Long peers_max;
	private Long peers_not_connected;
	private Long priority;
	private String priority_str = "";
	private Long ratio = null;
	private Long size_bytes;
	private Long size_chunks;
	private Long size_files;
	private Long skip_rate = null;
	private Long skip_total = null;
	private Long state = null;
	private Long state_changed = null;
	private String tied_to_file = null;
	private Long tracker_focus = null;
	private Long tracker_numwant = null;
	private Long tracker_size = null;
	private Long up_rate;
	private Long up_total;
	private Long uploads_max;
	private Long active;
	private Long hash_checked;
	private Long hash_checking;
	private Long multi_file;
	private Long open;
	private Long privat;
	
	transient private FileArrayList files = null;
	transient private PeerArrayList peers = null;
	transient private TrackerArrayList trackers = null;
	
	private boolean existing = false;
	private Server server = null;
	private PropertyChangeSupport propertyChangeSupport = null;
	
	public static final String PROP_CHANGED = "torrentPropChanged";
	public static final String PROP_FILES_CHANGED = "PROP_FILES_CHANGED";
	public static final String PROP_PEERS_CHANGED = "PROP_PEERS_CHANGED";
	public static final String PROP_TRACKERS_CHANGED = "PROP_TRACKERS_CHANGED";
	
	
	
	public Torrent(String base_filename, String base_path, Long bytes_done,
			Long chunk_size, Long chunks_hashed, Long complete,
			Long completed_bytes, Long completed_chunks,
			String connection_current, String connection_leech,
			String connection_seed, Long creation_date, String directory,
			Long down_rate, Long down_total, Long free_diskspace, String hash, Long hashing,
			Long ignore_commands, Long left_bytes, String local_id,  
			String local_id_html, Long max_file_size, String message,
			Long peers_min, String name, Long peer_exchange,
			Long peers_accounted, Long peers_complete,
			Long peers_connected, Long peers_max, Long peers_not_connected,
			Long priority, String priority_str, Long ratio, Long size_bytes,
			Long size_chunks, Long size_files, Long skip_rate, Long skip_total, Long state,
			Long state_changed, String tied_to_file, Long tracker_focus,
			Long tracker_numwant, Long tracker_size, Long up_rate,
			Long up_total, Long uploads_max, Long active,
			Long hash_checked, Long hash_checking, Long multi_file,
			Long open, Long privat,
			boolean existing, Server server) {
		super();
		this.base_filename = base_filename;
		this.base_path = base_path;
		this.bytes_done = bytes_done;
		this.chunk_size = chunk_size;
		this.chunks_hashed = chunks_hashed;
		this.complete = complete;
		this.completed_bytes = completed_bytes;
		this.completed_chunks = completed_chunks;
		this.connection_current = connection_current;
		this.connection_leech = connection_leech;
		this.connection_seed = connection_seed;
		this.creation_date = creation_date;
		this.directory = directory;
		this.down_rate = down_rate;
		this.down_total = down_total;
		this.free_diskspace = free_diskspace;
		this.hash = hash;
		this.hashing = hashing;
		this.ignore_commands = ignore_commands;
		this.left_bytes = left_bytes;
		this.local_id = local_id;
		this.local_id_html = local_id_html;
		this.max_file_size = max_file_size;
		this.message = message;
		this.peers_min = peers_min;
		this.name = name;
		this.peer_exchange = peer_exchange;
		this.peers_accounted = peers_accounted;
		this.peers_complete = peers_complete;
		this.peers_connected = peers_connected;
		this.peers_max = peers_max;
		this.peers_not_connected = peers_not_connected;
		this.priority = priority;
		this.priority_str = priority_str;
		this.ratio = ratio;
		this.size_bytes = size_bytes;
		this.size_chunks = size_chunks;
		this.size_files = size_files;
		this.skip_rate = skip_rate;
		this.skip_total = skip_total;
		this.state = state;
		this.state_changed = state_changed;
		this.tied_to_file = tied_to_file;
		this.tracker_focus = tracker_focus;
		this.tracker_numwant = tracker_numwant;
		this.tracker_size = tracker_size;
		this.up_rate = up_rate;
		this.up_total = up_total;
		this.uploads_max = uploads_max;
		this.active = active;
		this.hash_checked = hash_checked;
		this.hash_checking = hash_checking;
		this.multi_file = multi_file;
		this.open = open;
		this.privat = privat;
		this.existing = existing;
		this.server = server;
		
		this.files = new FileArrayList();
		
		propertyChangeSupport = new PropertyChangeSupport(this);
	}
	
	/**
	 * Updates this torrent with the new values.
	 * Dont notify propertychangelisteners, so update can be called from non gui thread.
	 * Returns 0 if no change occurred, 1 if a change occurred.
	 * @return
	 */
	public int update(String base_filename, String base_path, Long bytes_done,
			Long chunk_size, Long chunks_hashed, Long complete,
			Long completed_bytes, Long completed_chunks,
			String connection_current, String connection_leech,
			String connection_seed, Long creation_date, String directory,
			Long down_rate, Long down_total, Long free_diskspace, String hash, Long hashing,
			Long ignore_commands, Long left_bytes, String local_id,  
			String local_id_html, Long max_file_size, String message,
			Long peers_min, String name, Long peer_exchange,
			Long peers_accounted, Long peers_complete,
			Long peers_connected, Long peers_max, Long peers_not_connected,
			Long priority, String priority_str, Long ratio, Long size_bytes,
			Long size_chunks, Long size_files, Long skip_rate, Long skip_total, Long state,
			Long state_changed, String tied_to_file, Long tracker_focus,
			Long tracker_numwant, Long tracker_size, Long up_rate,
			Long up_total, Long uploads_max, Long active,
			Long hash_checked, Long hash_checking, Long multi_file,
			Long open, Long privat,
			boolean existing, Server server) {
		boolean changed = false;
		if (!this.base_filename.equals(base_filename)) { this.base_filename = base_filename; changed = true;}
		if (!this.base_path.equals(base_path)) { this.base_path = base_path; changed = true;}
		if (!this.bytes_done.equals(bytes_done)) { this.bytes_done = bytes_done; changed = true;}
		if (!this.chunk_size.equals(chunk_size)) { this.chunk_size = chunk_size; changed = true;}
		if (!this.chunks_hashed.equals(chunks_hashed)) { this.chunks_hashed = chunks_hashed; changed = true;}
		if (!this.complete.equals(complete)) { this.complete = complete; changed = true;}
		if (!this.completed_bytes.equals(completed_bytes)) { this.completed_bytes = completed_bytes; changed = true;}
		if (!this.completed_chunks.equals(completed_chunks)) { this.completed_chunks = completed_chunks; changed = true;}
		if (!this.connection_current.equals(connection_current)) { this.connection_current = connection_current; changed = true;}
		if (!this.connection_leech.equals(connection_leech)) { this.connection_leech = connection_leech; changed = true;}
		if (!this.connection_seed.equals(connection_seed)) { this.connection_seed = connection_seed; changed = true;}
		if (!this.creation_date.equals(creation_date)) { this.creation_date = creation_date; changed = true;}
		if (!this.directory.equals(directory)) { this.directory = directory; changed = true;}
		if (!this.down_rate.equals(down_rate)) { this.down_rate = down_rate; changed = true;}
		if (!this.down_total.equals(down_total)) { this.down_total = down_total; changed = true;}
		if (!this.free_diskspace.equals(free_diskspace)) { this.free_diskspace = free_diskspace; /* changed = true; */}
		if (!this.hash.equals(hash)) { this.hash = hash; changed = true;}
		if (!this.hashing.equals(hashing)) { this.hashing = hashing; changed = true;}
		if (!this.ignore_commands.equals(ignore_commands)) { this.ignore_commands = ignore_commands; changed = true;}
		if (!this.left_bytes.equals(left_bytes)) { this.left_bytes = left_bytes; changed = true;}
		if (!this.local_id.equals(local_id)) { this.local_id = local_id; changed = true;}
		if (!this.local_id_html.equals(local_id_html)) { this.local_id_html = local_id_html; changed = true;}
		if (!this.max_file_size.equals(max_file_size)) { this.max_file_size = max_file_size; changed = true;}
		if (!this.message.equals(message)) { this.message = message; changed = true;}
		if (!this.peers_min.equals(peers_min)) { this.peers_min = peers_min; changed = true;}
		if (!this.name.equals(name)) { this.name = name; changed = true;}
		if (!this.peer_exchange.equals(peer_exchange)) { this.peer_exchange = peer_exchange; changed = true;}
		if (!this.peers_accounted.equals(peers_accounted)) { this.peers_accounted = peers_accounted; changed = true;}
		if (!this.peers_complete.equals(peers_complete)) { this.peers_complete = peers_complete; changed = true;}
		if (!this.peers_connected.equals(peers_connected)) { this.peers_connected = peers_connected; changed = true;}
		if (!this.peers_max.equals(peers_max)) { this.peers_max = peers_max; changed = true;}
		if (!this.peers_not_connected.equals(peers_not_connected)) { this.peers_not_connected = peers_not_connected; changed = true;}
		if (!this.priority.equals(priority)) { this.priority = priority; changed = true;}
		if (!this.priority_str.equals(priority_str)) { this.priority_str = priority_str; changed = true;}
		if (!this.ratio.equals(ratio)) { this.ratio = ratio; changed = true;}
		if (!this.size_bytes.equals(size_bytes)) { this.size_bytes = size_bytes; changed = true;}
		if (!this.size_chunks.equals(size_chunks)) { this.size_chunks = size_chunks; changed = true;}
		if (!this.size_files.equals(size_files)) { this.size_files = size_files; changed = true;}
		if (!this.skip_rate.equals(skip_rate)) { this.skip_rate = skip_rate; changed = true;}
		if (!this.skip_total.equals(skip_total)) { this.skip_total = skip_total; changed = true;}
		if (!this.state.equals(state)) { this.state = state; changed = true;}
		if (!this.state_changed.equals(state_changed)) { this.state_changed = state_changed; changed = true;}
		if (!this.tied_to_file.equals(tied_to_file)) { this.tied_to_file = tied_to_file; changed = true;}
		if (!this.tracker_focus.equals(tracker_focus)) { this.tracker_focus = tracker_focus; changed = true;}
		if (!this.tracker_numwant.equals(tracker_numwant)) { this.tracker_numwant = tracker_numwant; changed = true;}
		if (!this.tracker_size.equals(tracker_size)) { this.tracker_size = tracker_size; changed = true;}
		if (!this.up_rate.equals(up_rate)) { this.up_rate = up_rate; changed = true;}
		if (!this.up_total.equals(up_total)) { this.up_total = up_total; changed = true;}
		if (!this.uploads_max.equals(uploads_max)) { this.uploads_max = uploads_max; changed = true;}
		if (!this.active.equals(active)) { this.active = active; changed = true;}
		if (!this.hash_checked.equals(hash_checked)) { this.hash_checked = hash_checked; changed = true;}
		if (!this.hash_checking.equals(hash_checking)) { this.hash_checking = hash_checking; changed = true;}
		if (!this.multi_file.equals(multi_file)) { this.multi_file = multi_file; changed = true;}
		if (!this.open.equals(open)) { this.open = open; changed = true;}
		if (!this.privat.equals(privat)) { this.privat = privat; changed = true;}
		this.existing = existing;
		this.server = server;
		
		if (changed)
		{	
			return 1;
		}
		else
			return 0;
	}
	
	
	public Long getDown_rate() {
		return down_rate;
	}


	public void setDown_rate(Long down_rate) {
		this.down_rate = down_rate;
		this.propertyChangeSupport.firePropertyChange(PROP_CHANGED, null, this.down_rate);
	}


	public Torrent() {
		super();
	}


	public String getBase_filename() {
		return base_filename;
	}
	public void setBase_filename(String base_filename) {
		this.base_filename = base_filename;
		this.propertyChangeSupport.firePropertyChange(PROP_CHANGED, null, this.base_filename);
	}
	public String getBase_path() {
		return base_path;
	}
	public void setBase_path(String base_path) {
		this.base_path = base_path;
		this.propertyChangeSupport.firePropertyChange(PROP_CHANGED, null, this.base_path);
	}
	public Long getBytes_done() {
		return bytes_done;
	}
	public void setBytes_done(Long bytes_done) {
		this.bytes_done = bytes_done;
		this.propertyChangeSupport.firePropertyChange(PROP_CHANGED, null, this.bytes_done);
	}
	public Long getChunk_size() {
		return chunk_size;
	}
	public void setChunk_size(Long chunk_size) {
		this.chunk_size = chunk_size;
		this.propertyChangeSupport.firePropertyChange(PROP_CHANGED, null, this.chunk_size);
	}
	public Long getChunks_hashed() {
		return chunks_hashed;
	}
	public void setChunks_hashed(Long chunks_hashed) {
		this.chunks_hashed = chunks_hashed;
		this.propertyChangeSupport.firePropertyChange(PROP_CHANGED, null, this.chunks_hashed);
	}
	public Long isComplete() {
		return complete;
	}
	public void setComplete(Long complete) {
		this.complete = complete;
		this.propertyChangeSupport.firePropertyChange(PROP_CHANGED, null, this.complete);
	}
	public Long getCompleted_bytes() {
		return completed_bytes;
	}
	public void setCompleted_bytes(Long completed_bytes) {
		this.completed_bytes = completed_bytes;
		this.propertyChangeSupport.firePropertyChange(PROP_CHANGED, null, this.completed_bytes);
	}
	public Long getCompleted_chunks() {
		return completed_chunks;
	}
	public void setCompleted_chunks(Long completed_chunks) {
		this.completed_chunks = completed_chunks;
		this.propertyChangeSupport.firePropertyChange(PROP_CHANGED, null, this.completed_chunks);
	}
	public String getConnection_current() {
		return connection_current;
	}
	public void setConnection_current(String connection_current) {
		this.connection_current = connection_current;
		this.propertyChangeSupport.firePropertyChange(PROP_CHANGED, null, this.connection_current);
	}
	public String getConnection_leech() {
		return connection_leech;
	}
	public void setConnection_leech(String connection_leech) {
		this.connection_leech = connection_leech;
		this.propertyChangeSupport.firePropertyChange(PROP_CHANGED, null, this.connection_leech);
	}
	public String getConnection_seed() {
		return connection_seed;
	}
	public void setConnection_seed(String connection_seed) {
		this.connection_seed = connection_seed;
		this.propertyChangeSupport.firePropertyChange(PROP_CHANGED, null, this.connection_seed);
	}
	public Long getCreation_date() {
		return creation_date;
	}
	public void setCreation_date(Long creation_date) {
		this.creation_date = creation_date;
		this.propertyChangeSupport.firePropertyChange(PROP_CHANGED, null, this.creation_date);
	}
	public String getDirectory() {
		return directory;
	}
	public void setDirectory(String directory) {
		this.directory = directory;
		this.propertyChangeSupport.firePropertyChange(PROP_CHANGED, null, this.directory);
	}
	public Long getDown_total() {
		return down_total;
	}
	public void setDown_total(Long down_total) {
		this.down_total = down_total;
		this.propertyChangeSupport.firePropertyChange(PROP_CHANGED, null, this.down_total);
	}
	public Long getFree_diskspace() {
		return free_diskspace;
	}
	public void setFree_diskspace(Long free_diskspace) {
		this.free_diskspace = free_diskspace;
		this.propertyChangeSupport.firePropertyChange(PROP_CHANGED, null, this.free_diskspace);
	}
	public String getHash() {
		return hash;
	}
	public void setHash(String hash) {
		this.hash = hash;
		this.propertyChangeSupport.firePropertyChange(PROP_CHANGED, null, this.hash);
	}
	public Long getHashing() {
		return hashing;
	}
	public void setHashing(Long hashing) {
		this.hashing = hashing;
		this.propertyChangeSupport.firePropertyChange(PROP_CHANGED, null, this.hashing);
	}
	public Long getIgnore_commands() {
		return ignore_commands;
	}
	public void setIgnore_commands(Long ignore_commands) {
		this.ignore_commands = ignore_commands;
		this.propertyChangeSupport.firePropertyChange(PROP_CHANGED, null, this.ignore_commands);
	}
	public Long getLeft_bytes() {
		return left_bytes;
	}
	public void setLeft_bytes(Long left_bytes) {
		this.left_bytes = left_bytes;
		this.propertyChangeSupport.firePropertyChange(PROP_CHANGED, null, this.left_bytes);
	}
	public String getLocal_id() {
		return local_id;
	}
	public void setLocal_id(String local_id) {
		this.local_id = local_id;
		this.propertyChangeSupport.firePropertyChange(PROP_CHANGED, null, this.local_id);
	}
	public String getLocal_id_html() {
		return local_id_html;
	}
	public void setLocal_id_html(String local_id_html) {
		this.local_id_html = local_id_html;
		this.propertyChangeSupport.firePropertyChange(PROP_CHANGED, null, this.local_id_html);
	}
	public Long getMax_file_size() {
		return max_file_size;
	}
	public void setMax_file_size(Long max_file_size) {
		this.max_file_size = max_file_size;
		this.propertyChangeSupport.firePropertyChange(PROP_CHANGED, null, this.max_file_size);
	}
	public String getMessage() {
		return message;
	}
	public void setMessage(String message) {
		this.message = message;
		this.propertyChangeSupport.firePropertyChange(PROP_CHANGED, null, this.message);
	}
	public Long getPeers_min() {
		return peers_min;
	}
	public void setPeers_min(Long peers_min) {
		this.peers_min = peers_min;
		this.propertyChangeSupport.firePropertyChange(PROP_CHANGED, null, this.peers_min);
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
		this.propertyChangeSupport.firePropertyChange(PROP_CHANGED, null, this.name);
	}
	public Long getPeer_exchange() {
		return peer_exchange;
	}
	public void setPeer_exchange(Long peer_exchange) {
		this.peer_exchange = peer_exchange;
		this.propertyChangeSupport.firePropertyChange(PROP_CHANGED, null, this.peer_exchange);
	}
	public Long getPeers_accounted() {
		return peers_accounted;
	}
	public void setPeers_accounted(Long peers_accounted) {
		this.peers_accounted = peers_accounted;
		this.propertyChangeSupport.firePropertyChange(PROP_CHANGED, null, this.peers_accounted);
	}
	public Long getPeers_complete() {
		return peers_complete;
	}
	public void setPeers_complete(Long peers_complete) {
		this.peers_complete = peers_complete;
		this.propertyChangeSupport.firePropertyChange(PROP_CHANGED, null, this.peers_complete);
	}
	public Long getPeers_connected() {
		return peers_connected;
	}
	public void setPeers_connected(Long peers_connected) {
		this.peers_connected = peers_connected;
		this.propertyChangeSupport.firePropertyChange(PROP_CHANGED, null, this.peers_connected);
	}
	public Long getPeers_max() {
		return peers_max;
	}
	public void setPeers_max(Long peers_max) {
		this.peers_max = peers_max;
		this.propertyChangeSupport.firePropertyChange(PROP_CHANGED, null, this.peers_max);
	}
	public Long getPeers_not_connected() {
		return peers_not_connected;
	}
	public void setPeers_not_connected(Long peers_not_connected) {
		this.peers_not_connected = peers_not_connected;
		this.propertyChangeSupport.firePropertyChange(PROP_CHANGED, null, this.peers_not_connected);
	}
	public Long getPriority() {
		return priority;
	}
	public void setPriority(Long priority) {
		this.priority = priority;
		this.propertyChangeSupport.firePropertyChange(PROP_CHANGED, null, this.priority);
	}
	public String getPriority_str() {
		return priority_str;
	}
	public void setPriority_str(String priority_str) {
		this.priority_str = priority_str;
		this.propertyChangeSupport.firePropertyChange(PROP_CHANGED, null, this.priority_str);
	}
	public Long getRatio() {
		return ratio;
	}
	public void setRatio(Long ratio) {
		this.ratio = ratio;
		this.propertyChangeSupport.firePropertyChange(PROP_CHANGED, null, this.ratio);
	}
	public Long getSize_bytes() {
		return size_bytes;
	}
	public void setSize_bytes(Long size_bytes) {
		this.size_bytes = size_bytes;
		this.propertyChangeSupport.firePropertyChange(PROP_CHANGED, null, this.size_bytes);
	}
	public Long getSize_chunks() {
		return size_chunks;
	}
	public void setSize_chunks(Long size_chunks) {
		this.size_chunks = size_chunks;
		this.propertyChangeSupport.firePropertyChange(PROP_CHANGED, null, this.size_chunks);
	}
	public Long getSkip_rate() {
		return skip_rate;
	}
	public void setSkip_rate(Long skip_rate) {
		this.skip_rate = skip_rate;
		this.propertyChangeSupport.firePropertyChange(PROP_CHANGED, null, this.skip_rate);
	}
	public Long getSkip_total() {
		return skip_total;
	}
	public void setSkip_total(Long skip_total) {
		this.skip_total = skip_total;
		this.propertyChangeSupport.firePropertyChange(PROP_CHANGED, null, this.skip_total);
	}
	public Long getState() {
		return state;
	}
	public void setState(Long state) {
		this.state = state;
		this.propertyChangeSupport.firePropertyChange(PROP_CHANGED, null, this.state);
	}
	public Long getState_changed() {
		return state_changed;
	}
	public void setState_changed(Long state_changed) {
		this.state_changed = state_changed;
		this.propertyChangeSupport.firePropertyChange(PROP_CHANGED, null, this.state_changed);
	}
	public String getTied_to_file() {
		return tied_to_file;
	}
	public void setTied_to_file(String tied_to_file) {
		this.tied_to_file = tied_to_file;
		this.propertyChangeSupport.firePropertyChange(PROP_CHANGED, null, this.tied_to_file);
	}
	public Long getTracker_focus() {
		return tracker_focus;
	}
	public void setTracker_focus(Long tracker_focus) {
		this.tracker_focus = tracker_focus;
		this.propertyChangeSupport.firePropertyChange(PROP_CHANGED, null, this.tracker_focus);
	}
	public Long getTracker_numwant() {
		return tracker_numwant;
	}
	public void setTracker_numwant(Long tracker_numwant) {
		this.tracker_numwant = tracker_numwant;
		this.propertyChangeSupport.firePropertyChange(PROP_CHANGED, null, this.tracker_numwant);
	}
	public Long getTracker_size() {
		return tracker_size;
	}
	public void setTracker_size(Long tracker_size) {
		this.tracker_size = tracker_size;
		this.propertyChangeSupport.firePropertyChange(PROP_CHANGED, null, this.tracker_size);
	}
	public Long getUp_rate() {
		return up_rate;
	}
	public void setUp_rate(Long up_rate) {
		this.up_rate = up_rate;
		this.propertyChangeSupport.firePropertyChange(PROP_CHANGED, null, this.up_rate);
	}
	public Long getUp_total() {
		return up_total;
	}
	public void setUp_total(Long up_total) {
		this.up_total = up_total;
		this.propertyChangeSupport.firePropertyChange(PROP_CHANGED, null, this.up_total);
	}
	public Long getUploads_max() {
		return uploads_max;
	}
	public void setUploads_max(Long uploads_max) {
		this.uploads_max = uploads_max;
		this.propertyChangeSupport.firePropertyChange(PROP_CHANGED, null, this.uploads_max);
	}
	public Long isActive() {
		return active;
	}
	public void setActive(Long active) {
		this.active = active;
		this.propertyChangeSupport.firePropertyChange(PROP_CHANGED, null, this.active);
	}
	public Long isHash_checked() {
		return hash_checked;
	}
	public void setHash_checked(Long hash_checked) {
		this.hash_checked = hash_checked;
		this.propertyChangeSupport.firePropertyChange(PROP_CHANGED, null, this.hash_checked);
	}
	public Long isHash_checking() {
		return hash_checking;
	}
	public void setHash_checking(Long hash_checking) {
		this.hash_checking = hash_checking;
		this.propertyChangeSupport.firePropertyChange(PROP_CHANGED, null, this.hash_checking);
	}
	public Long isMulti_file() {
		return multi_file;
	}
	public void setMulti_file(Long multi_file) {
		this.multi_file = multi_file;
		this.propertyChangeSupport.firePropertyChange(PROP_CHANGED, null, this.multi_file);
	}
	public Long isOpen() {
		return open;
	}
	public void setOpen(Long open) {
		this.open = open;
		this.propertyChangeSupport.firePropertyChange(PROP_CHANGED, null, this.open);
	}
	public Long isPrivat() {
		return privat;
	}
	public void setPrivat(Long privat) {
		this.privat = privat;
		this.propertyChangeSupport.firePropertyChange(PROP_CHANGED, null, this.privat);
	}
	
	public Long getSize_files() {
		return size_files;
	}

	public void setSize_files(Long size_files) {
		this.size_files = size_files;
		this.propertyChangeSupport.firePropertyChange(PROP_CHANGED, null, this.size_files);
	}
	
	public FileArrayList getFiles() {
		if (files == null)
			files = new FileArrayList();
		return files;
	}

	public void addFile(File file) {
//		if (files != this.files)
//			this.propertyChangeSupport.firePropertyChange(PROP_FILES_CHANGED, this.files, files);
		if (this.files == null)
			this.files = new FileArrayList();
		file.addPropertyChangeListener(this.files);
		this.files.add(file);
	}

	public PeerArrayList getPeers() {
		if (peers == null)
			peers = new PeerArrayList();
		return peers;
	}

	public void addPeer(Peer peer) {
		if (peers == null)
			peers = new PeerArrayList();
		peer.addPropertyChangeListener(this.peers);
		this.peers.add(peer);
	}

	public TrackerArrayList getTrackers() {
		if (this.trackers == null)
			this.trackers = new TrackerArrayList();
		return this.trackers;
	}

	public void addTracker(Tracker tracker) {
		if (this.trackers == null)
			this.trackers = new TrackerArrayList();
		tracker.addPropertyChangeListener(this.trackers);
		this.trackers.add(tracker);
	}

	/**
	 * Downloaded bytes in %
	 * @return
	 */
	public Integer getDonePercent()
	{
		Double d = (double)this.completed_bytes / (double)this.size_bytes * (double)100;
		return ((Double)Math.floor(d)).intValue();
	}
	
	/**
	 * Hashing in %
	 * @return
	 */
	public Integer getDoneHashedPercent()
	{
		Double d = (double)this.chunks_hashed / (double)this.size_chunks * (double)100;
		return ((Double)Math.floor(d)).intValue();
	}
	
	public Long getRemainingBytes()
	{
		return this.size_bytes - this.completed_bytes;
	}


	public String getRatioFormated() {
		DecimalFormat format = new DecimalFormat("#.##");
		
		return format.format((double)this.getRatio() / (double)1000);
	}
	
	/**
	 * Gets the eta in seconds
	 * @return eta in seconds, 0 if complete, Long.MAX_VALUE if infinite.
	 */
	public Long getETA()
	{
		if (this.getRemainingBytes() > 0)
		{
			if (this.getDown_rate() > 0)
			{
				return ((Long)this.getRemainingBytes() / this.getDown_rate());
			}
			else
				return Long.MAX_VALUE;
		}
		else return 0L;
	}
	
	public boolean isExisting() {
		return existing;
	}

	public void setExisting(boolean existing) {
		this.existing = existing;
	}
	
	public Server getServer() {
		return server;
	}
	
	public void addPropertyChangeListener(PropertyChangeListener listener)
	{
		propertyChangeSupport.addPropertyChangeListener(PROP_CHANGED, listener);
	}
	
	public void removePropertyChangeListener(PropertyChangeListener listener)
	{
		propertyChangeSupport.removePropertyChangeListener(PROP_CHANGED, listener);
	}
	
}
